home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / Graphics / Viewers / FastTIFF / TIFFView.m < prev    next >
Text File  |  1992-12-25  |  2KB  |  61 lines

  1. #import <sys/param.h>
  2. #import <strings.h>
  3. #import <appkit/View.h>
  4. #import <appkit/Button.h>
  5. #import <appkit/OpenPanel.h>
  6. #import <appkit/NXImage.h>
  7. #import <appkit/NXBitmapImageRep.h>
  8. #import "TIFFView.h"
  9.  
  10. @implementation TIFFView
  11.  
  12. - drawSelf:(NXRect *)rects :(int)count
  13. {
  14.      static NXPoint point = {0.0,0.0};
  15.  
  16.      if(isCached)
  17.       [image composite:NX_COPY toPoint:&point];
  18.      else
  19.       [image draw];
  20.  
  21.      return self;
  22. }
  23.  
  24. - openTIFF:sender
  25. {
  26.      char               file[MAXPATHLEN];
  27.      const char         *const *files;
  28.      static const char  *const imageType[4] = {"tiff"};
  29.      id                 openpanel = [[OpenPanel new] allowMultipleFiles:NO];
  30.  
  31.  
  32.      if([openpanel runModalForTypes:imageType])
  33.       if((files = [openpanel filenames]) && *files){
  34.                (void)strcat(strcat(strcpy(file,[openpanel directory]),"/"),*files);
  35.            if(image)
  36.             [image free];
  37.            if(bitmap = image = [[NXBitmapImageRep alloc] initFromFile:file]){
  38.             [self sizeTo:[image pixelsWide]:[image pixelsHigh]];
  39.             if(isCached)
  40.              [[(image = [[NXImage alloc] init]) setDataRetained:YES] useRepresentation:bitmap];
  41.             [[[self display] window] makeKeyAndOrderFront:self];
  42.            }
  43.            else
  44.             NXRunAlertPanel("Open Image","Error loading image!","Cancel",NULL,NULL);
  45.           }
  46.      
  47.      return self;
  48. }
  49.  
  50. - toggleCachingMode:sender
  51. {
  52.      if(isCached = !isCached)
  53.       [[(image = [[NXImage alloc] init]) setDataRetained:YES] useRepresentation:bitmap];
  54.      else
  55.       image = bitmap;
  56.  
  57.      return self;
  58. }
  59.  
  60. @end
  61.